package com.ccnu.sb;


import com.ccnu.sb.Listener.BootListenerEnvironmentPreparedEvent;
import com.ccnu.sb.Listener.BootListenerFailedEvent;
import com.ccnu.sb.Listener.BootListenerReadyEvent;
import com.ccnu.sb.Listener.BootListenerStartingEvent;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ExitCodeGenerator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@EnableScheduling
@EnableAsync
@ImportResource("classpath:/dubbo.xml")
@MapperScan("com.ccnu.sb.dao.impl")
@RestController
@SpringBootApplication
@EnableDubbo
public class SpringBootApp {
	private static Logger log = LoggerFactory.getLogger(SpringBootApp.class);

	// 通过注解方式获得配置文件中的值
	@Value("${server.servlet.context-path}")
	private String rootPath;
	
	@Bean
	public ExitCodeGenerator exitCodeGenerator() {
		return () -> 42;
	}

	@RequestMapping("/testboot")
	public String testBoot(){
		return "testboot";
	}
	
	public static void main(String[] args) {
		SpringApplication app = new SpringApplication(SpringBootApp.class);

		// 增加自定义的监听事件
		app.addListeners(new BootListenerStartingEvent());
		app.addListeners(new BootListenerEnvironmentPreparedEvent());
		app.addListeners(new BootListenerFailedEvent());
		app.addListeners(new BootListenerReadyEvent());
		app.run(args);
	}
}
